package com.sunxueqi.project.system.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunxueqi.common.constant.StatusConstants;
import com.sunxueqi.common.utils.KeyGenerate;
import com.sunxueqi.common.utils.SecurityUtils;
import com.sunxueqi.project.system.dao.DictTypeMapper;
import com.sunxueqi.project.system.service.IDictTypeService;
import com.sunxueqi.project.system.vo.DictType;

@Service
public class DictTypeServiceImpl implements IDictTypeService{

	@Autowired
	private DictTypeMapper dictTypeMapper;
	
	@Override
	public List<DictType> selectDictTypeList(DictType dictType) {
		dictType.setDeleteStatus(StatusConstants.NORMAL);
		return dictTypeMapper.selectList(dictType);
	}

	@Override
	public int add(DictType dictType) {
		dictType.setId(KeyGenerate.getKeyId());
		dictType.setDeleteStatus(StatusConstants.NORMAL);
		dictType.setCreateBy(SecurityUtils.getLoginUserId());
		dictType.setCreateTime(new Timestamp(System.currentTimeMillis()));
		return dictTypeMapper.insert(dictType);
	}

	@Override
	public int deleteDictTypeByIds(String[] idArray) {
		int result = 0;
		for(String id: idArray) {
			DictType dictType = new DictType();
			dictType.setId(id);
			dictType.setDeleteStatus(StatusConstants.DELETED);
			dictType.setDeleteTime(new Timestamp(System.currentTimeMillis()));
			dictType.setDeleteBy(SecurityUtils.getLoginUserId());
			int count = dictTypeMapper.updateByPrimaryKey(dictType);
			result += count;
		}
		return result;
	}

	@Override
	public int updateDictType(DictType dictType) {
		dictType.setUpdateTime(new Timestamp(System.currentTimeMillis()));
		dictType.setUpdateBy(SecurityUtils.getLoginUserId());
		int count = dictTypeMapper.updateByPrimaryKey(dictType);
		return count;
	}

	@Override
	public int changeStatus(DictType dictType) {
		return dictTypeMapper.updateByPrimaryKey(dictType);
	}

}
